/******************************************************************************/
#include "stdafx.h"
#include "Main.h"
/******************************************************************************/
NetChr::NetChr()
{
   scale=1;
}
/******************************************************************************/
Bool NetChr::create(ChrCreateRequest &ccr)
{
   if(!ccr.valid())return false;

   name =ccr.name;
   scale=ccr.size;
   mesh =ccr.obj->mesh();

   // setup character world and position
   Net ::World    *world   =Net::Worlds("world/mmo.world"); // starting world
   Game::Waypoint *waypoint=world->getWaypoint("start"); if(!waypoint->points.elms())Exit("no points in starting waypoint");
   setWorld(world, waypoint->points[0].pos+Vec(0, 0.5f*scale, 0)); // set world and position

   // add some items to the inventory
   inv.items.New().create("Obj/item/weapon/Sword/1/0.obj");
   inv.items.New().create("Obj/item/weapon/blunt/Mace/0.obj");

   return true;
}
/******************************************************************************/
void NetChr::leaveGame()
{
   super::leaveGame();

   name.del();
   mesh=NULL;
   inv.del();
}
/******************************************************************************/
void NetChr::compress(File &f)
{
   super::compress(f);

   f.putStr(name);
   f<<scale;
   DL.mesh.putStr(f, mesh.name());
   inv.compress(f);
}
Bool NetChr::decompress(File &f)
{
   super::decompress(f);

   f.getStr(name);
   f>>scale;
   mesh=DL.mesh.getStr(f);
   inv.decompress(f);
   return true;
}
/******************************************************************************/
void NetChr::save(File &f)
{
   super::save(f);

   f.putByte(0); // version

   f.putStr(name);
   f<<scale;
   f.putStr(mesh.name());
   inv.save(f);
}
Bool NetChr::load(File &f)
{
   if(super::load(f))switch(f.getByte()) // version
   {
      case 0:
      {
         f.getStr(name);
         f>>scale;
         mesh=f.getStr();
         if(!inv.load(f))return false;
      }return true;
   }
   return false;
}
Bool NetChr::load(Str name)
{
   File f; if(f.readStdTry(name))return load(f);
   return false;
}
/******************************************************************************/
